<?php defined('SYSPATH') or die();?>
<!doctype html>
<html>
<head size_float=RK6fkk >
    <meta charset="utf-8">
    <title>思途CMS{$coreVersion}</title>
    {template 'stourtravel/public/public_js'}
    {php echo Common::getCss('style.css,base.css,base_new.css'); }
    {php echo Common::getScript("uploadify/jquery.uploadify.min.js,jquery.buttonbox.js,choose.js"); }
    {php echo Common::getCss('uploadify.css','js/uploadify/'); }
</head>
<body style="overflow:hidden">

    <table class="content-tab">
        <tr>
            <td width="119px" class="content-lt-td" valign="top">
                {template 'stourtravel/public/leftnav'}
                <!--右侧内容区-->
            </td>
            <td valign="top" class="content-rt-td" style="overflow:hidden">
                <div class="cfg-header-bar">
                    <a href="javascript:;" class="fr btn btn-primary radius mt-6 mr-10" onclick="window.location.reload()">刷新</a>
                    <a href="javascript:;" class="fr btn btn-primary radius mt-6 mr-10" id="addbtn">添加</a>
                </div>

                <div class="cfg-search-bar" id="search_bar">
                    <div class="fl select-box w100 mt-3 ml-10">
                        <select name="channel_id" data-fieldname="channel_id" onchange="togStatusChange(this)" class="select">
                            {loop $channel_list $key $v}
                            <option value="{$v['id']}">{$v['title']}</option>
                            {/loop}
                        </select>
                    </div>
                    <span class="cfg-select-box btnbox mt-3 ml-10" id="website" data-url="box/index/type/weblist" data-result="result_webid">站点切换&nbsp;&gt;&nbsp;<span id="result_webid">全部</span><i class="arrow-icon"></i></span>
                    <span class="cfg-select-box btnbox mt-3 ml-10" id="destination" data-url="box/index/type/destlist" data-result="result_dest" >目的地&nbsp;&gt;&nbsp;<span id="result_dest">全部</span><i class="arrow-icon"></i></span>
                    <span class="cfg-select-box btnbox mt-3 ml-10" id="attrlist" data-url="box/index/type/attrlist/typeid/5" data-result="result_attrlist" >属性&nbsp;&gt;&nbsp;<span id="result_attrlist">全部</span><i class="arrow-icon"></i></span>
                    <div class="cfg-header-search">
                        <input type="text" id="searchkey" placeholder="景点名称/景点编号" datadef="景点名称/景点编号" class="search-text">
                        <a href="javascript:;" class="search-btn" onclick="CHOOSE.searchKeyword()">搜索</a>
                    </div>
                </div>
                <div id="product_grid_panel" class="content-nrt">

                </div>
            </td>
        </tr>
    </table>

<script>

//window.kindmenu = {$kindmenu};//分类设置菜单

window.display_mode = 1;	//默认显示模式
window.product_kindid = 0;  //默认目的地ID

Ext.onReady(
    function () {
        Ext.tip.QuickTipManager.init();

        $(".btnbox").buttonBox();

        $("#searchkey").focusEffect();
        //添加按钮
        $("#addbtn").click(function(){

            ST.Util.addTab('添加景点',SITEURL+'ferry/admin/ferry/add/{if isset($_GET['menuid'])}menuid/{$_GET['menuid']}/{/if}parentkey/product/itemid/4',0);
        });

        //产品store
        window.product_store = Ext.create('Ext.data.Store', {

            fields: [
                'id',
                'aid',
                'series',
                'webid',
                'title',
                'kindlist',
                'attrid',
                'ishidden',
                'fenxiao_status',
                'displayorder',
                'kindname',
                'iconlist',
                'attrname',
                'themelist',
                'tr_class',
                'tickettypeid',
                'jifenbook',
                'jifentprice',
                'jifencomment',
                'paytype',
                'tickettypename',
                'ferryid',
                'ticketid',
                'iconname',
                'suppliername',
                'linkman',
                'mobile',
                'qq',
                'address',
                'url',
                'price',
                'finaldestid',
                'finaldestname',
                'paytype_name',
                'day_before',
                'hour_before',
                'minute_before',
                'channel_name',
                'suit_day',
                'platform',
                'is_examine',
                'status'
            ],

            proxy: {
                type: 'ajax',
                api: {
                    read: SITEURL+'ferry/admin/ferry/ferry/action/read',  //读取数据的URL
                    update: SITEURL+'ferry/admin/ferry/ferry/action/save',
                    destroy: SITEURL+'ferry/admin/ferry/ferry/action/delete'
                },
                reader: {
                    type: 'json',   //获取数据的格式
                    root: 'lists',
                    totalProperty: 'total'
                }
            },

            remoteSort: true,
            pageSize: 20,
            autoLoad: true,
            listeners: {
                load: function (store, records, successful, eOpts) {

                    if(!successful){
                        ST.Util.showMsg("{__('norightmsg')}",5,1000);
                    }
                    var pageHtml=ST.Util.page(store.pageSize,store.currentPage,store.getTotalCount(),10);
                    $("#line_page").html(pageHtml);
                    window.product_grid.doLayout();
                    $(".pageContainer .pagePart a").click(function () {
                        var page = $(this).attr('page');
                        product_store.loadPage(page);
                    });

                }
            }

        });

        //产品列表
        window.product_grid = Ext.create('Ext.grid.Panel', {
            store: product_store,
            renderTo: 'product_grid_panel',
            border: 0,
            width: "100%",
            bodyBorder: 0,
            bodyStyle: 'border-width:0px',
            scroll:'vertical', //只要垂直滚动条
                bbar: Ext.create('Ext.toolbar.Toolbar', {
                store: product_store,  //这个和grid用的store一样
                displayInfo: true,
                emptyMsg: "没有数据了",
                items: [
                    {
                        xtype:'panel',
                        id:'listPagePanel',
                        html:'<div id="line_page"></div>'
                    },
                    {
                        xtype: 'combo',
                        fieldLabel: '每页显示数量',
                        width: 170,
                        labelAlign: 'right',
                        forceSelection: true,
                        value: 20,
                        store: {fields: ['num'], data: [
                            {num: 20},
                            {num: 40},
                            {num: 60}
                        ]},
                        displayField: 'num',
                        valueField: 'num',
                        listeners: {
                            select: CHOOSE.changeNum
                        }
                    }

                ],

                listeners: {
                    single: true,
                    render: function (bar) {
                        var items = this.items;
                      //  bar.down('tbfill').hide();

                        bar.insert(0, Ext.create('Ext.panel.Panel', {border: 0, html: '<div class="panel_bar">' +
                                '<a class="btn btn-primary radius" href="javascript:void(0);" onclick="CHOOSE.chooseAll()">全选</a>' +
                                '<a class="btn btn-primary radius ml-10" href="javascript:void(0);" onclick="CHOOSE.chooseDiff()">反选</a>' +
                                '<a class="btn btn-primary radius ml-10" href="javascript:void(0);" onclick="CHOOSE.delMore()">删除</a>' +
                                '<a class="btn btn-primary radius ml-10" href="javascript:void(0);" onclick="CHOOSE.batchCommission(5,{$_GET['menuid']})">批量设置抽佣</a>' +
                                '</div>'}));
                        bar.insert(1, Ext.create('Ext.panel.Panel', {border: 0, items: [
                            {
                                xtype: 'button',
                                text: '批量设置',
                                cls:'my-extjs-btn',
                                menu: {
                                    cls: 'menu-no-icon',
                                    width: "82px",
                                    shadow: false,
                                    items: [

                                        {
                                            text: '目的地', handler: function () {
                                            CHOOSE.setSome("设置目的地", {
                                                loadCallback: setDests,
                                                maxHeight: 500
                                            }, SITEURL + 'destination/dialog_setdest');
                                        }
                                        },
                                        {
                                            text: '属性', handler: function () {
                                            CHOOSE.setSome("设置属性", {loadCallback: setAttrids}, SITEURL + 'attrid/dialog_setattrid?typeid=5');
                                           }
                                        },
                                        {
                                            text: '图标', handler: function () {
                                            CHOOSE.setSome("设置图标", {loadCallback: setIcons}, SITEURL + 'icon/dialog_seticon?typeid=5');
                                        }
                                        },
                                        {
                                            text: '显示端',handler: function () {
                                                let num=0
                                                $(".product_check:checked").each(function(index,element){
                                                    num++;
                                                });
                                                if(num>50){
                                                    ST.Util.showMsg("最多选择50条！",5,2000);
                                                    return false
                                                }
                                                if(!num){
                                                    ST.Util.showMsg("请选择！",5,2000);
                                                    return false
                                                }
                                                let ids = []
                                                $(".product_check:checked").each(function(index,element){
                                                    var id=$(element).val();
                                                    ids.push(id)
                                                });
                                                addClient(ids.join(','))
                                            }
                                        },
                                        {
                                            text: '下架',handler: function () {
                                                let num=0
                                                $(".product_check:checked").each(function(index,element){
                                                    num++;
                                                });
                                                if(num>50){
                                                    ST.Util.showMsg("最多选择50条！",5,2000);
                                                    return false
                                                }
                                                if(!num){
                                                    ST.Util.showMsg("请选择！",5,2000);
                                                    return false
                                                }
                                                let ids = []
                                                $(".product_check:checked").each(function(index,element){
                                                    var id=$(element).val();
                                                    ids.push(id)
                                                });
                                                ids = ids.join(',')
                                                Ext.Ajax.request({
                                                    url:   "/newtravel/platformset/ajax_set",
                                                    method: "post",
                                                    datatype: "JSON",
                                                    params: {id: ids, typeid: 5, platform:''},
                                                    success: function (response, opts) {
                                                        if (response.responseText == 'ok') {
                                                            let list =ids.split(',');
                                                            var record;
                                                            for(let i=0;i<list.length;i++){
                                                                record =window.product_store.getById(list[i].toString())
                                                                record.set('platform','未设');
                                                                record.commit();
                                                            }
                                                        }
                                                    }
                                                });
                                            }
                                        },
                                        {
                                            text: '关闭分销',handler: function () {
                                                let num=0
                                                $(".product_check:checked").each(function(index,element){
                                                    num++;
                                                });
                                                if(num>50){
                                                    ST.Util.showMsg("最多选择50条！",5,2000);
                                                    return false
                                                }
                                                if(!num){
                                                    ST.Util.showMsg("请选择！",5,2000);
                                                    return false
                                                }
                                                $(".product_check:checked").each(function(index,element){
                                                    var id=$(element).val();
                                                    updateField(null,id,'fenxiao_status',0)
                                                });
                                            }
                                        },
                                        {
                                            text: '开启分销',handler: function () {
                                                let num=0
                                                $(".product_check:checked").each(function(index,element){
                                                    num++;
                                                });
                                                if(num>50){
                                                    ST.Util.showMsg("最多选择50条！",5,2000);
                                                    return false
                                                }
                                                if(!num){
                                                    ST.Util.showMsg("请选择！",5,2000);
                                                    return false
                                                }
                                                $(".product_check:checked").each(function(index,element){
                                                    var id=$(element).val();
                                                    updateField(null,id,'fenxiao_status',1)
                                                });
                                            }
                                        }
                                    ]
                                }

                            }
                        ]}));
                        bar.insert(2, Ext.create('Ext.toolbar.Fill'));
                    }
                }
            }),
            columns: [
                {
                    text: '选择',
                    width: '6%',
                    // xtype:'templatecolumn',
                    tdCls: 'product-ch',
                    align: 'center',
                    dataIndex: 'id',
                    menuDisabled:true,
                    border: 0,
                    renderer: function (value, metadata, record) {
                        id = record.get('id');
                        if (id.indexOf('suit') == -1)
                            return  "<input type='checkbox' class='product_check' style='cursor:pointer' id='box_"+id+"' value='" + value + "'/>";
                    }
                },
                {
                    text: '排序',
                    width: '6%',
                    dataIndex: 'displayorder',
                    tdCls: 'product-order',
                    id: 'column_lineorder',
                    menuDisabled:true,
                    cls:'sort-col',
                    align: 'center',
                    border: 0,
                    renderer: function (value, metadata, record) {
                        var id = record.get('id');
                        var newvalue=value;
                        if(value==9999||value==999999||!value)
                            newvalue='';
                        return "<input type='text' value='"+newvalue+"' class='row-edit-txt' onblur=\"updateField(this,'"+id+"','displayorder',0,'input')\"/>";
                    }
                },
                {
                    text:'编号',
                    width:'6%',
                    dataIndex:'series',
                    align:'center',
                    id:'column_series',
                    menuDisabled:true,
                    border:0,
                    sortable:false,
                    renderer : function(value, metadata,record) {
                        return '<span>'+value+'</span>';
                    }
                },
                {
                    text: '景点名称',
                    width: '10%',
                    dataIndex: 'title',
                    menuDisabled:true,
                    align: 'left',
                    border: 0,
                    sortable: false,
                    renderer: function (value, metadata, record) {
                        var aid = record.get('aid');
                        var id = record.get('id');
                        var ticketid = record.get('ticketid');
                        var ferryid = record.get('ferryid');
                        var iconname = record.get('iconname');
                        var url = record.get('url');
                        if (!isNaN(id))
                            return "<a href='"+url+"' class='product-title' target='_blank'>" + value +iconname+ "</a>";
                        else if (id.indexOf('suit') != -1) {
                            metadata.tdAttr = "data-qtip='点击跳转到门票设置页面'  data-qclass='dest-tip'";
                            return "<a href='javascript:void(0);'  onclick=\"modSuit('"+ticketid+"','"+ferryid+"')\"  class='suit-title'>&bull;&nbsp;&nbsp;" + value + "</a>";
                        }
                    },
                    listeners: {
                        afterrender: function (obj, eopts) {
                            if (window.display_mode == 1) {
                                obj.width = '33%';
                            }
                            else {
                                obj.width = '23%';
                            }
                        }
                    }
                },
                {
                    text: '报价有效期'+ST.Util.getGridHelp('line_validity'),
                    width: '8%',
                    align: 'center',
                    dataIndex:'suit_day',
                    border: 0,
                    menuDisabled:true,
                    cls: 'mod-1 sort-col',
                    sortable: true,
                    renderer: function (value, metadata, record) {
                        var curdate=new Date();
                        var id=record.get('id');
                        var curtimestamp=curdate.getTime();
                        var date=new Date(value*1000);
                        if(value && value>0) {
                            var color=value*1000<curtimestamp?'red':'green';
                            return '<span style="color:'+color+'">' + Ext.Date.format(date, 'Y-m-d') + '</span>';
                        }
                        else if(value==-1) {
                            return '<span class="c-999">无套餐 </span>';
                        }
                        else
                        {
                            var str = id.indexOf('suit') == -1 ? '部分未报价' : '未报价';
                            return '<span style="color:red">' + str + '</span>';
                        }

                    },
                    listeners: {
                        afterrender: function (obj, eopts) {

                            if (window.display_mode != 1 && window.display_mode!=2)
                                obj.hide();
                            else
                                obj.show();
                        }
                    }
                },
                {
                    text: '目的地',
                    width: '7%',
                    dataIndex: 'kindlist',
                    menuDisabled:true,
                    align: 'center',
                    cls: 'mod-1 sort-col',
                    sortable: true,
                    renderer: function (value, metadata, record, rowIndex, colIndex) {

                        var kindname=record.get('kindname');
                        var finaldestname=record.get('finaldestname');
                        if(kindname) {
                            kindname=kindname.replace(finaldestname,'<font color="red">'+finaldestname+'</font>');
                            metadata.tdAttr = "data-qtip='" + kindname + "'" + "data-qclass='dest-tip'";
                        }
                        var id=record.get('id');
                        var d_text=value?'<span class="c-green">已设</span>':'<span class="c-999">未设</span>';

                        return "<a href='javascript:void(0);' onclick=\"setOneDests("+id+")\">"+d_text+"</a>";
                        // return getExpandableImage(value, metadata,record);
                    },
                    listeners: {
                        afterrender: function (obj, eopts) {

                            if (window.display_mode != 1)
                                obj.hide();
                            else
                                obj.show();
                        }
                    }
                },
                {
                    text: '图标',
                    width: '7%',
                    align: 'center',
                    dataIndex: 'iconlist',
                    border: 0,
                    menuDisabled:true,
                    cls: 'mod-1 sort-col',
                    sortable: true,
                    renderer: function (value, metadata, record, rowIndex, colIndex) {

                        var id = record.get('id');
                        var d_text=value?'<span class="c-green">已设</span>':'<span class="c-999">未设</span>';
                        return "<a href='javascript:void(0);' onclick=\"setOneIcons("+id+")\">" + d_text + "</a>";
                    },
                    listeners: {
                        afterrender: function (obj, eopts) {

                            if (window.display_mode != 1)
                                obj.hide();
                            else
                                obj.show();
                        }
                    }
                },
                {
                    text: '属性',
                    width: '8%',
                    align: 'center',
                    dataIndex: 'attrid',
                    border: 0,
                    sortable: true,
                    menuDisabled:true,
                    cls: 'mod-1 sort-col',
                    renderer: function (value, metadata, record, rowIndex, colIndex) {

                        var attrname = record.get('attrname');
                        if (attrname)
                            metadata.tdAttr = "data-qtip='" + attrname + "'data-qclass='dest-tip'";

                        var id = record.get('id');
                        var d_text=value?'<span class="c-green">已设</span>':'<span class="c-999">未设</span>';
                        return "<a href='javascript:void(0);' onclick=\"setOneAttrids("+id+")\">" + d_text + "</a>";
                        // return getExpandableImage(value, metadata,record);
                    },
                    listeners: {
                        afterrender: function (obj, eopts) {

                            if (window.display_mode != 1)
                                obj.hide();
                            else
                                obj.show();
                        }
                    }
                },
                {
                    text: '显示'+ST.Util.getGridHelp('platform_grid'),
                    width: '7%',
                    align: 'center',
                    border: 0,
                    dataIndex: 'platform',
                    sortable:false,
                    locked: false,
                    menuDisabled:true,
                    renderer: function (value, metadata, record) {
                        var id = record.get('id');
                        var is_examine = record.get('is_examine');
                        if(is_examine==1){
                            return '<img title="审核中" alt="审核中"  role="button" ' +
                                ' src="" ' +
                                'class="x-action-col-icon x-action-col-0 dest-status-wait">'
                        }else{
                            return "<a href='javascript:;' onclick='addClient("+id+")' class='btn-link'>"+value+"</a>";
                        }

                    },
                    listeners: {
                        afterrender: function (obj, eopts) {

                            if (window.display_mode != 1)
                                obj.hide();
                            else
                                obj.show();

                        }
                    }
                },
                {
                    text: '允许分销',
                    width: '5%',
                    // xtype:'templatecolumn',
                    align: 'center',
                    border: 0,
                    dataIndex: 'fenxiao_status',
                    menuDisabled:true,
                    xtype: 'actioncolumn',
                    cls: 'mod-1 sort-col',
                    items: [
                        {
                            getClass: function (v, meta, rec) {          // Or return a class from a function
                                if (v == 1)
                                    return 'dest-status-ok';
                                else
                                    return 'dest-status-none';
                            },
                            handler: function (view, index, colindex, itm, e, record) {
                                var val = record.get('fenxiao_status');
                                var id = record.get('id');
                                var newval = val == 1 ? 0 : 1;
                                updateField(null, record.get('id'), 'fenxiao_status', newval)
                            }
                        }
                    ],
                    listeners: {
                        afterrender: function (obj, eopts) {

                            if (window.display_mode != 1)
                                obj.hide();
                            else
                                obj.show();
                        }
                    }
                },
                {
                    text: '管理',
                    width: '8%',
                    align: 'center',
                    border: 0,
                    sortable: false,
                    menuDisabled:true,
                    cls: 'mod-1',
                    renderer: function (value, metadata, record) {

                        var id = record.get('id');
                        return "<a href='javascript:void(0);' title='编辑' class='btn-link' onclick=\"goModify(" + id + ")\">编辑</a>";
                    },
                    listeners: {
                        afterrender: function (obj, eopts) {
                            if (window.display_mode != 1)
                                obj.hide();
                            else
                                obj.show();
                        }
                    }
                }
            ],
            listeners: {
                boxready: function () {
                    var height = Ext.dom.Element.getViewportHeight();
                    this.maxHeight=height-76;
                    this.doLayout();
                },
                afterlayout: function (grid) {

                    if (window.product_kindname) {
                        Ext.getCmp('column_lineorder').setText(window.product_kindname + '-排序')
                    }
                    else {
                        Ext.getCmp('column_lineorder').setText('排序')
                    }

                    window.product_store.each(function (record) {
                        id = record.get('id');

                        if (id.indexOf('suit') != -1) {

                            var ele = window.product_grid.getView().getNode(record);
                            var cls = record.get('tr_class');
                            Ext.get(ele).addCls(cls);
                            Ext.get(ele).setVisibilityMode(Ext.Element.DISPLAY);
                            if (window.display_mode != 2 && window.display_mode!=3) {
                                Ext.get(ele).hide();
                            }
                            else {
                                Ext.get(ele).show();
                            }
                        }
                        else if (window.display_mode == 2) {
                            var ele = window.product_grid.getView().getNode(record);
                            var cls = record.get('tr_class');
                            Ext.get(ele).addCls(cls);
                        }
                    });

                    var data_height = 0;
                    try {
                        data_height = grid.getView().getEl().down('.x-grid-table').getHeight();
                    } catch (e) {
                    }
                    var height = Ext.dom.Element.getViewportHeight();
                    if (data_height > height - 76) {
                        window.has_biged = true;
                        grid.height = height - 76;
                    }
                    else if (data_height < height - 76) {
                        if (window.has_biged) {
                            window.has_biged = false;
                            grid.doLayout();
                        }
                    }
                }
            },
            plugins: [
                Ext.create('Ext.grid.plugin.CellEditing', {
                    clicksToEdit: 2,
                    listeners: {
                        edit: function (editor, e) {
                            var id = e.record.get('id');
                            updateField(0, id, e.field, e.value, 0);
                            return false;
                        },
                        beforeedit: function (editor, e) {
                            if (e.field == 'jifentprice' || e.field == 'jifenbook' || e.field == 'jifencomment' || e.field == 'paytype') {
                                var id = e.record.get('id');
                                if (id.indexOf('suit') == -1) {
                                    return false;
                                }
                            }
                        }
                    }
                })
            ],
            viewConfig: {
                enableTextSelection:true
            }
        });
    })

//实现动态窗口大小
Ext.EventManager.onWindowResize(function () {
    var height = Ext.dom.Element.getViewportHeight();
    var data_height = window.product_grid.getView().getEl().down('.x-grid-table').getHeight();
    if (data_height > height - 76)
        window.product_grid.height = (height - 76);

    window.product_grid.doLayout();


})



// 编辑显示端
function addClient(id){
    // 添加菜单页面
    ST.Util.showBox('编辑显示端','/newtravel/platformset/index?typeid=5&id='+id,400,200,null,null,document,{loadWindow:window,loadCallback: function (result, bool){
            if(!bool){
                return
            }
            Ext.Ajax.request({
                url:   "/newtravel/platformset/ajax_set",
                method: "post",
                datatype: "JSON",
                params: {id: result.id, typeid: 5, platform: result.platform},
                success: function (response, opts) {
                    if (response.responseText == 'ok') {
                        let list =result.id.split(',');
                        var record;
                        for(let i=0;i<list.length;i++){
                            record =window.product_store.getById(list[i].toString())
                            record.set('platform',result.platform_str?result.platform_str:'未设');
                            record.commit();
                        }

                    }
                }
            });

        }});
}


//更新某个字段
function updateField(ele, id, field, value, type,callback) {
    var record = window.product_store.getById(id.toString());
    if (type == 'select'||type=='input') {
        value = Ext.get(ele).getValue();
    }
    var view_el = window.product_grid.getView().getEl();


    Ext.Ajax.request({
        url: "ferry/action/update",
        method: "POST",
        datatype: "JSON",
        params: {id: id, field: field, val: value, kindid: window.product_kindid},
        success: function (response, opts) {
            if (response.responseText == 'ok') {
                // var view_el=window.product_grid.getView().getEl()
                //  var scroll_top=view_el.getScrollTop();

                record.set(field, value);
                record.commit();
                if(typeof(callback)=='function')
                {
                    callback(record);
                }

                // view_el.scrollBy(0,scroll_top,false);
            }
            else{

                    ST.Util.showMsg("{__('norightmsg')}",5,1000);

            }
        }});

}


//删除套餐
function delSuit(id) {
    ST.Util.confirmBox("提示","确定删除？",function(){
            window.product_store.getById(id).destroy();
    })
}





//门票管理
function ticketList(id,ferryname)
{
    var url = SITEURL+'ferry/admin/ferry/ticket/{if isset($_GET['menuid'])}menuid/{$_GET['menuid']}/{/if}parentkey/product/itemid/4/ferryid/'+id;
    ST.Util.addTab(ferryname,url);

}
//景点修改
function goModify(id)
{
    var record=window.product_store.getById(id.toString());
    var title = record.get('title');
    var url = SITEURL+'ferry/admin/ferry/edit/{if isset($_GET['menuid'])}menuid/{$_GET['menuid']}/{/if}parentkey/product/itemid/4/id/'+id;

    parent.window.addTab('修改-'+title,url,1);
}
//modSuit
function modSuit(ticketid,ferryid)
{
    var record=window.product_store.getById('suit_'+ticketid);

    var title = record.get('title');
    var url = SITEURL+'ferry/admin/ferry/ticket_op/{if isset($_GET['menuid'])}menuid/{$_GET['menuid']}/{/if}parentkey/product/itemid/4/action/edit/ferryid/'+ferryid+'/ticketid/'+ticketid;
    ST.Util.addTab('修改-'+title,url);
}

//设置多个线路的目的地
function setDests(result,bool)
{
    if(!bool)
        return;
    var ids=[];
    var destNames=[];
    for(var i in result.data)
    {
        var arr=result.data;
        ids.push(arr[i]['id']);
        destNames.push(arr[i]['kindname']);
    }
    var idsStr=ids.join(',');
    var destNamesStr=destNames.join(',');
    if(result.id)
    {
        if(result.finalDest) {
            updateField(null, result.id, 'finaldestid', result.finalDest.id, 0, function (record) {
                record.set('finaldestname', result.finalDest.kindname);
                record.commit();
            });
        }
        updateField(null,result.id,'kindlist',idsStr,0,function(record){
            record.set('kindname',destNamesStr);
            record.commit();
           // var id=record.get('id');
           // $("#box_"+id).attr("checked",true);
        });
        return;
    }

    $(".product_check:checked").each(function(index,element){
        var id=$(element).val();
        updateField(null,id,'kindlist',idsStr,0,function(record){
            record.set('kindname',destNamesStr);
            record.commit();
           // var id=record.get('id');
           // $("#box_"+id).attr("checked",true);
        });
    });


}
//设置属性
function setAttrids(result,bool)
{
    if(!bool)
        return;
    var ids=[];
    var names=[];
    for(var i in result.data)
    {
        var arr=result.data;
        ids.push(arr[i]['id']);
        names.push(arr[i]['attrname']);
    }
    var idsStr=ids.join(',');
    var nameStr=names.join(',');
    if(result.id)
    {
        updateField(null,result.id,'attrid',idsStr,0,function(record){
            record.set('attrname',nameStr);
            record.commit();
            var id=record.get('id');
            $("#box_"+id).attr("checked",true);
        });
        return;
    }
    $(".product_check:checked").each(function(index,element){
        var id=$(element).val();
        updateField(null,id,'attrid',idsStr,0,function(record){
            record.set('attrname',nameStr);
            record.commit();
           // var id=record.get('id');
           // $("#box_"+id).attr("checked",true);
        });
    });

}
function setIcons(result,bool)
{
    if(!bool)
        return;
    var ids=[];
    for(var i in result.data)
    {
        var oneId=result.data[i]['id'];
        ids.push(oneId);
    }
    var idsStr=ids.join(',');
    if(result.id)
    {
        updateField(null,result.id,'iconlist',idsStr,0);
        return;
    }
    $(".product_check:checked").each(function(index,element){
        var id=$(element).val();
        updateField(null,id,'iconlist',idsStr,0,function(record){
           // var id=record.get('id');
            //$("#box_"+id).attr("checked",true);
        });
    });

}
function setThemes(result,bool)
{
    if(!bool)
        return;
    var ids=[];
    var names=[];
    for(var i in result.data)
    {
        var row=result.data[i];
        ids.push(row['id']);
        names.push(row['ztname']);
    }
    var idsStr=ids.join(',');
    var nameStr=names.join(',');
    if(result.id)
    {
        updateField(null,result.id,'themelist',idsStr,0);
        return;
    }
    $(".product_check:checked").each(function(index,element){
        var id=$(element).val();
        updateField(null,id,'themelist',idsStr,0,function(record){
           // var id=record.get('id');
          //  $("#box_"+id).attr("checked",true);
        });
    });
}
function setOneDests(id)
{
    CHOOSE.setSome("设置目的地",{loadCallback:setDests,maxHeight:500},SITEURL+'destination/dialog_setdest?typeid=5&id='+id,true);

}
function setOneIcons(id)
{
    //CHOOSE.setSome("设置图标",{loadCallback:setIcons},SITEURL+'icon/dialog_seticon?typeid=5&id='+id,true);
    CHOOSE.setSome("设置图标",{loadCallback:setIcons,maxHeight:500},SITEURL+'icon/dialog_seticon_new?typeid=5&id='+id,true);
}
function setOneAttrids(id)
{
    CHOOSE.setSome("设置属性",{loadCallback:setAttrids},SITEURL+'attrid/dialog_setattrid?typeid=5&id='+id,true);
}
function setOneThemes(id)
{
    CHOOSE.setSome("设置专题",{loadCallback:setThemes},SITEURL+'theme/dialog_settheme?typeid=5&id='+id,true);
}
//供应商审核
function supplierCheckBox(id)
{
    var suitid = id.replace('suit_','');
    ST.Util.showBox("审核",SITEURL+'ferry/admin/ferry/dialog_supplier_check?suitid='+suitid,500,'',null,null,document,{loadWindow: window, loadCallback: setSupplierCheck});
}
//执行审核
function setSupplierCheck(result,bool)
{
    Ext.Ajax.request({
        url   :  SITEURL+"ferry/admin/ferry/dialog_supplier_check",
        method  :  "get",
        datatype  :  "JSON",
        params:{suitid:result.suitid,action:'save',status:result.data.status,refuse_msg:result.data.refuse_msg},
        success  :  function(response, opts)
        {
            if(response.responseText=='ok')
            {
                window.product_store.reload();
            }
        }});


}
/**
 * 状态改变
 * @param ele
 */
function togStatusChange(ele){
    var v=$(ele).val();
    var fieldname = $(ele).data('fieldname');

    window.product_store.getProxy().setExtraParam(fieldname,v);
    window.product_store.loadPage(1);

}
</script>

</body>
</html>
